<!-- @format -->

<!--用户管理-->
<template>
    <div>
        <a-card>
            <p slot="title">
                检索条件
            </p>
            <div class="formSearch">
                <a-form layout="inline" @keydown.native.enter.prevent="handleSubmit">
                    <a-form-item label="关键字：" prop="searchKey">
                        <a-input v-model="searchKey" @keyup="formatEnterContent(searchKey)"
                                 @blur="formatEnterContent(searchKey)" placeholder="请输入用户名搜索"
                                 style="width: 200px">
                            <a-icon slot="prefix" type="user" class="displayPre" />
                            <a-icon v-if="searchKey" slot="suffix" type="close-circle" @click="emitEmpty(searchKey)" />
                        </a-input>
                    </a-form-item>
                    <a-form-item label="组织机构：" prop="orgId" v-if="perms.sysOrg">
                        <a-tree-select
                                style="width: 200px"
                                :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
                                :treeData="getOrgTree" v-model="orgId" allowClear placeholder="全部">
                            <span style="color: #08c" slot="title" slot-scope="{key, title}">{{title}}</span>
                        </a-tree-select>
                    </a-form-item>
                    <a-form-item label="角色：" prop="roleId">
                        <a-select v-model="roleId" style="width:180px" allowClear placeholder="全部">
                            <a-select-option v-for="item in roles" :value="item.value" :key="item.value"
                                             v-show="flags != item.value">
                                {{ item.label }}
                            </a-select-option>
                        </a-select>
                    </a-form-item>
                    <a-button type="primary" @click="handleSubmit"
                              v-if="perms.findSysUser">查询
                    </a-button>
                    <a-button style="margin-left: 8px" @click="reStore">重置</a-button>
                </a-form>
            </div>
        </a-card>
        <div style="height: 15px"></div>
        <div class="commonStyle nyContent">
            <div class="table-operator">
                <a-button type="primary" @click="addUser" v-if="perms.addSysUser">新增</a-button>
                <a-button type="primary" @click="importUser" v-if="perms.addSysUser">导入</a-button>
                <a-button type="danger" @click="delUser" v-if="perms.batchDelSysUsers">批量删除</a-button>
            </div>
            <a-table :columns="columns" :dataSource="getSysUserDtos" :rowKey="record => record.id"
                     :row-selection="rowSelection"
                     :pagination="false">
                            <span slot="index" slot-scope="text, record, index">
                                {{ (page.currentPage - 1) * page.pageSize + index + 1 }}
                            </span>
                <span slot="validStatus" slot-scope="text"  :style="text !== '1'?'color:green':''">
                   {{ text === '1' ? '启用' : '停用' }}
                  </span>
                <span slot="roleType" slot-scope="text">
                    {{text ==='1'?'管理员':text ==='2'?'操作员':'审计员'}}
                  </span>
                <span slot="operation" slot-scope="text" class="table-operation">
                    <template v-if="text.protective === '0'">
                        <a @click="editSysUser(text)"
                           v-if="perms.editButtonShow ">编辑</a>
                        <a @click="enableSysUser(text)"
                           v-if="perms.enableShow && text.validStatus === '0' ">启用</a>
                                <a @click="disableSysUser(text)"
                                   v-if="perms.disableShow && text.validStatus === '1' ">禁用</a>
                                <a @click="userAuthShow(text)" v-if="perms.userAuthShow">用户权限管理</a>
                    </template>
                    <template v-if="curLoginType ==='UKEY' && text.protective !== '1'">
                        <a @click="openUKeyAuth(text)" v-if="text.authStatus !=='1' && text.validStatus === '1' && curLoginType ==='UKEY'">授权</a>
                        <a @click="unUKeyAuth(text.userName,text.protective)"
                           v-if="text.authStatus ==='1' && text.validStatus === '1' && curLoginType ==='UKEY'">撤销授权</a>
                    </template>
                    <a @click="resetRetryCount(text.userName)"
                       v-if="perms.userUnlockShow && text.locked">用户解锁</a>
                            </span>
            </a-table>
            <Page :totalCount="pageVal.total" :currentPage="pageVal.currentPage" ref="page"
                  :pageSize="pageVal.pageSize" @changePage="changePage" @changePageSize="changePageSize" />
        </div>
        <add-edit
                ref="addEdit"
                :title="title"
                :orgTree="getOrgTree"
                :fromRoleOpts="fromRoleOpts"
                :perms="perms"
                :sysUserDtos="sysUserDtos"
                @init="init"
        />
      <import-user
          ref="importUser"
          :title="title"
          :orgTree="getOrgTree"
          :fromRoleOpts="fromRoleOpts"
          :perms="perms"
          :sysUserDtos="sysUserDtos"
          @init="init"
      />
        <reset-pin-code ref="resetPinCode" />
        <init-ukey-auth ref="initUkeyAuth" @init="init" />
        <div class="spinBox" v-if="spinning">{{spinText}}</div>
    </div>
</template>

<script>
    import addEdit from './addEdit.vue'
    import importUser from './importUser.vue'
    import Page from 'module/pagination'
    import Util from '@/libs/util'

    const Base64 = require ('js-base64').Base64
    import * as State from 'libs/baseStateConts'
    import resetPinCode from 'module/resetPinCode'
    import initUkeyAuth from 'module/initUkeyAuth.vue'
    import { mapState, mapActions } from 'vuex'
    export default {
        name: 'userInfo',
        components: {
          importUser,
            addEdit,
            Page,
            resetPinCode,
            initUkeyAuth
        },
        data () {
            return {
                selectedRowKeys: [],
                title: true,
                showAddTable: false,
                showDelTable: false,
                searchKey: '',
                roleId: undefined,
                orgId: undefined,
                orgName: '',
                flags: '',
                array: [ 10, 20, 30, 40 ],
                /*选中的记录*/
                checkData: [],
                selectedNode: {},
                sysUserDtos: {
                    id: '',
                    userName: '',
                    password: '',
                    orgId: '',
                    orgName: '',
                    roleId: '',
                    name: '',
                    sfzjh: '',
                    phoneNum: '',
                    validStatus: ''
                },
                perms: {},
                page: {
                    currentPage: 1,
                    pageSize: 10
                },
                columns: [
                    {title: '序号', key: 'index', width: '7%', align: 'center', scopedSlots: {customRender: 'index'}},
                    {title: '用户名', dataIndex: 'userName', key: 'userName'},
                    {title: '用户姓名', dataIndex: 'name', key: 'name'},
                     {title: '用户角色', dataIndex: 'roleName', key: 'roleName'},
                    {title: '所属组织机构', dataIndex: 'orgName', key: 'orgName'},
                    {title: '手机号码', dataIndex: 'phoneNum', key: 'phoneNum'},
                    {
                        title: '启用状态',
                        dataIndex: 'validStatus',
                        key: 'validStatus',
                        scopedSlots: {customRender: 'validStatus'}
                    },
                    {title: '操作', key: 'operation', scopedSlots: {customRender: 'operation'}}
                ],
                roles: [],
                fromRoleOpts: [],
                showUKeyAuth: false,
                msg: '',
                curLoginType: sessionStorage.getItem('curLoginType'),
                selectedRows:[],
                userKey:{},
                spinText:'请稍后...',
                spinning:false,
            }
        },
        computed: {
            getSysUserDtos () {
                return this.$store.state.user.sysUserDtos
            },
            ...mapState ({
                pageVal: state => state.user.page,
                qsBackData: state => state.common.qsBackData,
            }),
            getOrgTree () {
                return this.$store.state.sysOrg.sysOrgTree
            },
            rowSelection() {
                return {
                    onChange: (selectedRowKeys, selectedRows) => {
                        this.selectedRowKeys = selectedRowKeys
                        this.selectedRows = selectedRows
                    },
                    getCheckboxProps: record => ({
                        props: {
                            disabled: record.userName === 'admin', // Column configuration not to be checked
                            name: record.userName,
                        },
                    }),
                };
            },
            ...mapState('global', {
                qsLibAll: state => state.qsLibAll
            }),
        },
        methods: {
            emitEmpty () {
                this.searchKey = ''
                this.init ()
            },
            reStore () {
                this.searchKey = ''
                this.orgId = undefined
                this.roleId = undefined
                this.page.currentPage = 1
                this.init ()
            },
            /**
             * Function    : onSelectChange
             * Description : 选择当前行id
             * Input       : none
             * Return      : none
             */
            onSelectChange ( selectedRowKeys ) {
                this.selectedRowKeys = selectedRowKeys
            },
            /*
             * 过滤输入框输入的特殊字符
             * */
            formatEnterContent ( value ) {
                let a = Util.clearSpecialChart (value)
                this.searchKey = a
            },
            /**
             * Function    : init
             * Description : 初始化列表
             * Input       : none
             * Return      : none
             */
            init () {
                let para = Object.assign (
                  {},
                  {
                      searchKey:
                        this.searchKey.trim ().length === 0
                          ? ''
                          : this.searchKey.trim ().length > 64
                          ? this.searchKey.trim ().slice (0, 64)
                          : this.searchKey.trim ()
                  },
                  {roleId: this.roleId, orgId: this.orgId, orgName: this.orgName},
                  this.page
                )
                this.selectedRowKeys = []
                this.$store.dispatch ('findSysUsersAct', para)
                this.$store.commit ('setQueryPara', para)
            },

            /**
             * Function    : addUser
             * Description : 新增用户
             * Input       : none
             * Return      : none
             */
            addUser () {
                let orgId = this.getOrgTree[ 0 ].id
                let orgName = this.getOrgTree[ 0 ].title
                this.sysUserDtos = {
                    id: '',
                    userName: '',
                    password: '',
                    roleId: '',
                    orgId: orgId,
                    orgName: orgName,
                    name: '',
                    sfzjh: '',
                    phoneNum: '',
                    validStatus: ''
                }
                this.title = true
                this.$refs.addEdit.showModal ()

                /**
                 * 更新from表单选定的组织机构下的角色
                 */
                this.$store.dispatch ('loadOrgsRolesAct', {orgId: orgId}).then (response => {
                    this.fromRoleOpts = response
                    this.title = true
                    this.$refs.addEdit.showModal ()
                })
            },

          /**
             * Function    : importUser
             * Description : 导入用户
             * Input       : none
             * Return      : none
             */
          importUser () {
                let orgId = this.getOrgTree[ 0 ].id
                let orgName = this.getOrgTree[ 0 ].title
                this.sysUserDtos = {
                    userName: '',
                    roleId: '',
                    orgId: orgId,
                    orgName: orgName,
                    name: '',
                }
                this.title = true
                this.$refs.importUser.showModal ()

                /**
                 * 更新from表单选定的组织机构下的角色
                 */
                this.$store.dispatch ('loadOrgsRolesAct', {orgId: orgId}).then (response => {
                    this.fromRoleOpts = response
                    this.title = true
                    this.$refs.importUser.showModal ()
                })
            },

            /**
             * Function    : checkCol
             * Description : 选择框事件
             * Input       : sel
             * Return      : none
             */
            checkCol ( sel ) {
                let check = []
                sel.forEach (( item, index ) => {
                    check.push (item)
                })
                this.checkData = check
            },

            /**
             * Function    : delUser
             * Description : 批量删除用户信息
             * Input       : none
             * Return      : none
             */
            delUser () {
                var ids = ''
                var cArry = []
                let checkChooseDataRs = true
                this.selectedRows.forEach (( item, index ) => {
                    if (item.protective === '1') {
                        this.$message.info ('"' + item.userName + '"是系统默认用户禁止删除')
                        checkChooseDataRs = false
                        return
                    }
                    if (index === 0) {
                        ids = item.id
                    } else {
                        ids += ',' + item.id
                    }
                    cArry.push (index)
                })
                if (!checkChooseDataRs) {
                    cArry = []
                    return
                }
                if (this.selectedRowKeys.length <= 0) {
                    cArry = []
                    this.$message.info ('请至少选择一条用户记录', 3)
                    return
                }
                ids = this.selectedRowKeys.join (',')
                this.$confirm ({
                    title: '确认删除选中的用户信息吗？',
                    onOk: () => {
                        let _this = this
                        _this.spinning = true
                        this.$store.dispatch ('batchDelSysUsersAct', {ids: ids}).then (response => {
                            if (response.code === 0) {
                                if (cArry.length === _this.getSysUserDtos.length && _this.page.currentPage > 1) {
                                    _this.page.currentPage = _this.page.currentPage - 1
                                }
                                _this.init ()
                                _this.$message.success (response.message)
                                _this.selectedRows = []
                                _this.selectedRowKeys = []
                            } else {
                                _this.$message.error (response.message)
                            }
                            ids = ''
                            cArry = []
                            _this.spinning = false
                        })
                    },
                    onCancel: () => {
                        ids = ''
                        cArry = []
                    }
                })
            },



            /**
             * Function    : editSysUser
             * Description : 修改系统用户信息
             * Input       : userName 用户名
             * Return      : none
             */
            editSysUser ( rowData ) {
                let _this = this
                //let orgId = rowData.orgId
                let orgId = this.getOrgTree[ 0 ].id
                _this.$store.dispatch ('getUserRoleAct', {userId: rowData.id}).then (res => {
                    this.$store.dispatch ('loadOrgsRolesAct', {orgId: orgId}).then (response => {
                        _this.fromRoleOpts = response
                        let roleId = res.id
                        _this.sysUserDtos = Object.assign ({}, rowData, {roleId: roleId})
                        _this.title = false
                        _this.$refs.addEdit.showEdit (_this.sysUserDtos)
                    })
                })
            },

            /**
             * Function    : resetRetryCount
             * Description : 用户解锁
             * Input       : userName 用户名
             * Return      : none
             */
            resetRetryCount ( userName ) {
                this.$confirm ({
                    title: `确定解锁${userName}用户吗?`,
                    okText: '确定',
                    cancelText: '取消',
                    onOk: () => {
                        this.$store.dispatch ('resetRetryCountAct', {userName: userName}).then (response => {
                            if (response.code === 0) {
                                this.$message.success (response.message)
                                this.init ()
                            } else {
                                this.$message.error (response.message)
                            }
                        })
                    }
                })
            },
            /**
             * Function    : enableSysUser
             * Description : 用户启用
             * Input       : userName 用户名
             * Return      : none
             */
            enableSysUser ( text ) {
                this.$confirm ({
                    title: `确定启用${text.userName}用户吗?`,
                    okText: '确定',
                    cancelText: '取消',
                    onOk: () => {
                        this.spinning = true
                        this.$store.dispatch ('enableSysUserAct', {ids: text.id}).then (response => {
                            if (response.code === 0) {
                                this.$message.success (response.message)
                                this.init ()
                            } else {
                                this.$message.error (response.message)
                            }
                            this.spinning = false
                        })
                    }
                })
            },
            /**
             * Function    : enableSysUser
             * Description : 用户启用
             * Input       : userName 用户名
             * Return      : none
             */
            disableSysUser ( text ) {
                this.$confirm ({
                    title: `确定禁用${text.userName}用户吗?`,
                    onOk: () => {
                        this.spinning = true
                        this.$store.dispatch ('disableSysUserAct', {ids: text.id}).then (response => {
                            if (response.code === 0) {
                                this.$message.success (response.message)
                                this.init ()
                            } else {
                                this.$message.error (response.message)
                            }
                            this.spinning = false
                        })
                    }
                })
            },
            /**
             * Function    : userAuthShow
             * Description : 用户权限管理
             * Input       : userName 用户名
             * Return      : none
             */
            userAuthShow ( text ) {
                let query = {
                    id: text.id,
                    name: text.name,
                    orgName: text.orgName,
                    userName: text.userName
                }
                this.$router.push ({
                    name: 'userAuth',
                    query: query
                })
            },

            /**
             * Function    : changePage
             * Description : 切换页码
             * Input       :  val
             * Return      : none
             */
            changePage ( val ) {
                this.page.currentPage = val
                this.init ()
            },

            /**
             * Function    : changePageSize
             * Description : 切换每页条数
             * Input       :  vm
             * Return      : none
             */
            changePageSize ( vm ) {
                this.page.pageSize = vm
                this.page.currentPage = 1
                this.init ()
            },

            /**
             * Function    : handleSubmit
             * Description : 查询按钮
             * Input       :  none
             * Return      : none
             */
            handleSubmit () {
                this.page.currentPage = 1
                this.init ()
            },

            /**
             * Function    : selectNodeId
             * Description :
             * Input       :  val
             * Return      : none
             */
            selectNodeId ( val ) {
                this.orgId = val.id
                this.orgName = val.name
            },

            /**
             * Function    : initPermission
             * Description : 初始化权限码
             * Input       : none
             * Return      : none
             */
            initPermission () {
                this.perms = {
                    findSysUser: this.hasPermission ('sysuser:findSysUser'),
                    editButtonShow: this.hasPermission ('sysuser:updSysUser'),
                    userUnlockShow: this.hasPermission ('sysuser:resetRetryCount'),
                    userAuthShow: this.hasPermission ('sysuser:userAuth'),
                    enableShow: this.hasPermission ('sysuser:enableSysUsers'),
                    disableShow: this.hasPermission ('sysuser:disableSysUsers'),
                    addSysUser: this.hasPermission ('sysuser:addSysUser'),
                    batchDelSysUsers: this.hasPermission ('sysuser:batchDelSysUsers'),
                    sysOrg: this.hasPermission ('system:sysOrg'),
                    addUserRole: this.hasPermission ('sysuser:addUserRole'),
                    resetPinCode: this.hasPermission ('authmanager:resetPinCode'),
                    makeAuthUKey: this.hasPermission ('authmanager:makeAuthUKeyToUser'),
                    cancelAuthUKey: this.hasPermission ('authmanager:cancelUserAuthUKey')
                }
            },
            /**
             * Function    : 重置用户PIN码
             * Description : 选择框事件
             * Input       : sel
             * Return      : none
             */
            resetPinCode () {
                this.$refs.resetPinCode.showModal ()
            },
            /**
             * Function    : openUKeyAuth
             * Description : 打开UKey授权对话框
             * Input       : rowData 操作行记录信息
             * Return      : None
             */
            openUKeyAuth ( rowData ) {
                this.$refs.initUkeyAuth.showUserModal (rowData, 'user')
            },

            /**
             * 开启扫描UKey设备定时器
             */
            startScanTimer () {
                let _this = this
                if (_this.scanUKeyTimer !== -1) {
                    return
                }

                //开启扫描外接密钥存储设备定时器
                _this.scanUKeyTimer = setInterval (function () {
                    _this.updDevSerialNum ()
                }, 1000 * 200)
            },

            /**
             * 关闭扫描UKey设备定时器
             */
            clearScanTimer () {
                let _this = this
                //关闭定时器、并且提示用户出错信息
                if (_this.scanUKeyTimer === -1) {
                    return
                }
                clearInterval (_this.scanUKeyTimer)
                _this.scanUKeyTimer = -1
            },

            /**
             * 更新UKey设备序列号
             */
            updDevSerialNum () {
                let _this = this
                let getAuthDevUri = '/ukeyauth/getAuthDevSerialNum'
                if (_this.isProtectiveUser) {
                    getAuthDevUri = '/ukeyauth/getDeviceSerialNum'
                }
                _this.$axios.get (this.$uurl + getAuthDevUri).then (response => {
                    let respData = response.data
                    _this.showLoadUrl = false
                    if (respData.code > 0 || respData.data === '') {

                        _this.uKeyDevFrom.serialNum = ''
                        _this.uKeyDevFrom.pinCode = ''

                        _this.authCtlflag.loginBtnCtl = true
                        _this.authCtlflag.authBtnCtl = true

                        _this.nullMsg = respData.message
                        return
                    }

                    if (_this.uKeyDevFrom.serialNum !== respData.data) {
                        _this.uKeyDevFrom.pinCode = ''
                        _this.uKeyDevFrom.serialNum = respData.data
                        _this.nullMsg = ''
                        _this.authCtlflag.authBtnCtl = true
                        _this.authCtlflag.loginBtnCtl = false
                        return
                    }
                }).catch (e => {
                    _this.clearScanTimer ()
                    _this.showLoadUrl = true
                    // _this.$Message.error ("未安装或未正常启动商密客户端");
                })
            },

            /**
             * Function    : downLoadUkeyDevice
             * Description : 下载U盾认证登录驱动
             * Input       : None
             * Return      : None
             */
            downLoadUkeyDevice () {
                document.getElementById ('ifile').src = State.downloadUKeyAuthTool
            },

            /**
             * Function    : logonDev
             * Description : UKey设备PIN码验证登录
             * Input       : rowData 操作行记录信息
             * Return      : None
             */
            logonDev ( fromName ) {
                let _this = this
                this.$refs[ fromName ].validate (( valid ) => {
                    if (valid) {
                        /**
                         * UKey设备PIN码验证登录
                         */
                        _this.msg = ''
                        let params = {pinCode: Base64.encode (_this.uKeyDevFrom.pinCode)}
                        let skLoginDevUri = '/ukeyauth/skLoginAuthDev'
                        if (_this.isProtectiveUser) {
                            skLoginDevUri = '/ukeyauth/skLoginDev'
                        }
                        this.$axios.get (this.$uurl + skLoginDevUri, {params: params}).then (response => {
                            let respData = response.data
                            if (respData.code !== 0) {
                                _this.msg = respData.message
                                return
                            }
                            //修改授权按钮状态
                            _this.authCtlflag.authBtnCtl = false
                            _this.authCtlflag.loginBtnCtl = true

                            _this.$message.success ('安全UKey验证登录成功')
                            // _this.checkAndAuthUKey('uKeyDevFrom');
                        }).catch (e => {
                            _this.msg = '调用UKey端登录接口失败'
                        })
                    }
                })
            },

            /**
             * Function    : checkAndAuthUKey
             * Description : 验证授权设备并且UKey授权
             * Input       : fromName 授权表单信息
             * Return      : None
             */
            checkAndAuthUKey ( fromName ) {
                let _this = this
                _this.authCtlflag.authBtnCtl = true
                let params = {isFristAuthUKey: _this.isProtectiveUser}
                _this.$axios.get (_this.$uurl + '/ukeyauth/existsSymmetryKeys', {params: params}).then (response => {
                    let respData = response.data
                    if (respData.code !== 0) {
                        _this.authCtlflag.authBtnCtl = false
                        _this.$message.error (respData.message)
                        return
                    }

                    if (respData.data) {
                        //已授权设备初始化处理
                        _this.handleInitAuthDev (fromName)
                    } else {
                        //执行UKey与用户授权
                        _this.uKeyAuth (fromName)
                    }
                    _this.authCtlflag.authBtnCtl = false
                }).catch (e => {
                    _this.authCtlflag.authBtnCtl = false
                })
            },

            /**
             * Function    : handleInitAuthDev
             * Description : 已授权设备初始化处理
             * Input       : fromName 授权表单信息
             * Return      : None
             */
            handleInitAuthDev ( fromName ) {
                /**
                 * 获取授权设备的系统用户信息
                 */
                let _this = this
                let authType = _this.isProtectiveUser ? State.LOGIC_NUM_TRUE : State.LOGIC_NUM_FALSE
                let params = Object.assign ({}, {authType: authType})
                _this.$axios.post (_this.$uurl + '/authmanager/loadUserUKeyAuthInfo', params, {}).then (response => {
                    let respData = response.data
                    if (respData.code !== 0) {
                        _this.$message.error (respData.message)
                        return
                    }

                    /**
                     * 验证服务端的授权情况
                     */
                    params = Object.assign ({}, respData.data)
                    this.$store.dispatch ('getUserAuthUKeyAct', params).then (response => {
                        if (response.code !== 0) {
                            _this.$message.error (response.message)
                            return
                        }

                        //设备内存储与后台系统存在授权信息
                        let data = response.data
                        if (data.authStatus === State.LOGIC_NUM_TRUE) {
                            _this.$message.error ('UKey已授权系统用户“' + respData.data.userName + '”，请更换新的UKey')
                        } else {
                            this.$confirm ({
                                content: 'UKey存在系统用户“' + respData.data.userName + '”授权信息，确定重置吗？',
                                onOk: () => {
                                    /**
                                     * 系统已经解绑，则重置UKey授权信息
                                     */
                                    params = Object.assign ({}, {authType: authType})
                                    _this.$axios.post (this.$uurl + '/authmanager/resetUserUKeyAuthInfo', params, {}).then (response => {
                                        let respData = response.data
                                        if (respData.code === 0) {
                                            //执行UKey与用户授权
                                            _this.uKeyAuth (fromName)
                                        } else {
                                            this.$message.error (respData.message)
                                        }
                                    })
                                },
                                onCancel: () => {
                                }
                            })

                        }
                    })
                })
            },

            /**
             * Function    : uKeyAuth
             * Description : UKey授权
             * Input       : fromName 授权表单信息
             * Return      : None
             */
            uKeyAuth ( fromName ) {
                let _this = this
                let authType = _this.isProtectiveUser ? State.LOGIC_NUM_TRUE : State.LOGIC_NUM_FALSE
                let params = {
                    userName: _this.uKeyDevFrom.userName,
                    authType: authType
                }

                _this.authCtlflag.authBtnCtl = true
                /**
                 * 生成授权请求参数
                 */
                this.$axios.post (this.$uurl + '/authmanager/ganRequestAuthParams', params, {}).then (response => {
                    let respData = response.data
                    if (respData.code !== 0) {
                        _this.authCtlflag.authBtnCtl = false
                        this.$message.error (respData.message)
                        return
                    }

                    /**
                     * 生成授权信息，并服务存储
                     */
                    params = Object.assign ({}, respData.data)
                    this.$store.dispatch ('makeAuthUKeyToUserAct', params).then (response => {
                        if (response.code !== 0) {
                            _this.authCtlflag.authBtnCtl = false
                            /**
                             * UKEY绑定系统用户失败，则删除初始化的授权容器
                             */
                            params = Object.assign ({}, {authType: authType})
                            _this.$axios.post (this.$uurl + '/authmanager/resetUserUKeyAuthInfo', params, {})
                            this.$message.error (response.message)
                        } else {
                            /**
                             * 授权认证信息写入UKey
                             */
                            params = Object.assign ({}, response.data)
                            this.$axios.post (this.$uurl + '/authmanager/saveUserUKeyAuthInfo', params, {}).then (response => {
                                let respData = response.data
                                if (respData.code !== 0) {
                                    //生成撤销授权参数
                                    params = Object.assign ({}, {
                                        userName: _this.uKeyDevFrom.userName,
                                        authType: authType
                                    })
                                    this.$axios.post (this.$uurl + '/authmanager/ganCancelAuthInfoParams', params, {}).then (response => {
                                        let respData = response.data
                                        if (respData.code === 0) {
                                            //请求撤销本次授权
                                            this.$store.dispatch ('cancelUserAuthUKeyAct', respData)
                                        }
                                    }).catch (e => {
                                    })

                                    _this.authCtlflag.authBtnCtl = false
                                    this.$message.error ('写入安全UKey授权信息失败')
                                    return
                                }

                                /**
                                 * 自动关闭授权对话框
                                 */
                                _this.cancelAuthUKey (fromName)
                                _this.isProtectiveUser = false
                                this.init ()
                                this.$message.success (respData.message)
                            }).catch (e => {
                            })
                        }

                    })

                }).catch (e => {
                })
            },

            /**
             * Function    : cancelAuthUKey
             * Description : 取消授权操作
             * Input       : fromName 授权表单信息
             * Return      : None
             */
            cancelAuthUKey ( fromName ) {
                let _this = this
                _this.showUKeyAuth = false
                //清空表单信息
                _this.$refs[ fromName ].resetFields ()

                /**
                 * 初始化表单操作按钮状态
                 */
                _this.authCtlflag.authBtnCtl = true
                _this.authCtlflag.loginBtnCtl = true

                //关闭扫描外接UKey设备定时器
                _this.clearScanTimer ()
            },

            /**
             * Function    : unUKeyAuth
             * Description : 撤销UKey授权
             * Input       : fromName 授权表单信息
             * Return      : None
             */
            unUKeyAuth ( userName) {
                let _this = this
                this.$post('api/sysuser/unbindUserUkey',{username:userName}).then(res => {
                    if (res.code === 0) {
                        _this.$message.success(res.message)
                        _this.init()
                    } else {
                        _this.$message.error(res.message)
                    }
                })
            },
            ...mapActions('global', ['setGlobalState']),
        },
        /**
         * Function    : created
         * Description : 钩子函数
         * Input       : none
         * Return      : none
         */
        created () {
            // 加载角色列表
            this.initPermission ()
            this.$store.dispatch ('loadRolesAct').then (response => {
                this.roles = response
            })
            this.searchKey = this.$route.query.searchKey === undefined ? '' : this.$route.query.searchKey
            this.orgId = this.$route.query.orgId === undefined ? undefined : this.$route.query.orgId
            this.orgName = this.$route.query.orgName === undefined ? '' : this.$route.query.orgName
            this.roleId = this.$route.query.roleId === undefined ? undefined : this.$route.query.roleId

            /**
             * 屏蔽操作列
             */
            let sliceLen = 6
            if (!this.perms.sysOrg) {
                this.columns = this.columns.filter (item => {
                    if (item.key !== 'orgName') {
                        return item
                    }
                })
                sliceLen = sliceLen - 1
            }

            if (
              !this.perms.editButtonShow &&
              !this.perms.userAuthShow &&
              !this.perms.userUnlockShow &&
              !this.perms.enableShow &&
              !this.perms.disableShow
            ) {
                this.columns = this.columns.slice (0, sliceLen)
            }

            /**
             * 屏蔽复选框列
             */
            if (!this.perms.batchDelSysUsers) {
                this.columns = this.columns.slice (0)
            }

            this.$store.dispatch ('loadSysOrgTreeAct')
            this.init ()
            let _this = this

            setTimeout(()=>{
                //_this.qsLibAll.checkAuthUKey ('12222222')
            },4000)
        },
        mounted () {
            this.selectedNode = {
                id: this.orgId,
                name: this.orgName
            }
        },
        destroyed () {
            //关闭扫描外接UKey设备定时器
            this.clearScanTimer ()
        }
    }
</script>
